﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace PenguinForce
{
    public class ActionMap
    {
        public ActionMap(PlayerIndex playerIndex)
        {
            this.PlayerIndex = playerIndex;
            this.CurrentGamePadState = this.PreviousGamePadState = GamePad.GetState(this.PlayerIndex);
        }

        #region Properties

        public PlayerIndex PlayerIndex { get; private set; }

        private GamePadState PreviousGamePadState { get; set; }

        public GamePadState CurrentGamePadState { get; private set; }

        #endregion

        #region Methods

        public void BeginUpdate()
        {
            this.CurrentGamePadState = GamePad.GetState(this.PlayerIndex);
        }

        public void EndUpdate()
        {
            this.PreviousGamePadState = this.CurrentGamePadState;
        }

        public bool IsButtonHit(Buttons button)
        {
            return this.CurrentGamePadState.IsButtonUp(button) && this.PreviousGamePadState.IsButtonDown(button);
        }

        public bool IsPauseHit()
        {
            return this.IsButtonHit(Buttons.Back) || this.IsButtonHit(Buttons.Start);
        }

        #endregion
    }
}